<template>
  <div class="dialog-container">
    <div class="dialog-content">
      <el-form size="mini" :model="form" :rules="rules" ref="form" label-width="200" class="form">
        <el-form-item label="选择订单" prop="order_uid">
          <el-select v-model="form.order_uid" placeholder="请选择">
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="button-item">
          <div class="popup-bottom">
            <el-button size="mini" @click="handleCancel">取消</el-button>
            <el-button size="mini" type="primary" @click="handleConfirm" :disabled="form.order_uid === ''">确定</el-button>
          </div>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { apiOvoOrders, apiBindOrder } from '@/api/quotationPay'
import { formatFormData } from '@/utils/index'

export default {
  props: {
    info: Object,
  },
  data() {
    return {
      options: [],
      form: {
        order_uid: '',
      },
      rules: {
        order_uid: [{ required: true, message: '请选择订单', trigger: 'blur' }],
      },
    }
  },
  computed: {},
  mounted() {
    this.init()
    this.getOrderList()
  },
  methods: {
    init() {
      this.form.order_uid = this.info.order_uid
    },
    // 获取订单列表
    getOrderList() {
      apiOvoOrders().then((res) => {
        this.options = res.data
      })
    },
    // 取消
    handleCancel() {
      this.$emit('close')
    },
    // 确定
    handleConfirm() {
      apiBindOrder(
        formatFormData({
          id: this.info.id,
          order_uid: this.form.order_uid,
        })
      ).then((res) => {
        this.$message({
          message: '绑定成功',
          type: 'success',
        })
        this.$emit('refresh')
      })
    },
  },
}
</script>
<style lang="scss" scoped>
.dialog-container {
  padding: 0 24px;
}
.button-item {
  margin-top: 50px;
  text-align: right;
}
</style>
